package com.heima.article.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 交换机与对列的创建
 */
//@Configuration
public class FanoutConfiguration {

    /**
     * 声明交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange");
    }


    /**
     * 声明消息队列
     * @return
     */
    @Bean
    public Queue fanoutQueue() {
        return new Queue("fanoutQueue");
    }


    /**
     * 绑定消息队列与交换机
     * @return
     */
    @Bean
    public Binding fanoutBinding(Queue fanoutQueue, FanoutExchange fanoutExchange) {

        return BindingBuilder.bind(fanoutQueue).to(fanoutExchange);
    }
}
